import { FormSchema } from '/@/components/Form/index';
import { getBookList, deleteBook } from '/@/api/book/book';

export interface SearchOption {
  page: number;
  limit: number;
  title?: string;
  author?: string;
}

export const searchList = async (params: SearchOption) => {
  // console.log("🚀 ~ searchList ~ params:", params)
  const result: any[] = [];
  const { data, count } = await getBookList(params)
  // console.log("🚀 ~ searchList ~ data:", data)
  for (let i = 0; i < data.length; i++) {
    let el = data[i];
    result.push({
      id: el.id,
      title: el.title,
      description: [el.category.name, el.language],
      content: el.author,
      publisher: el.publisher,
      time: el.createDt,
      cover: el.cover,
    });
  }
  // console.log("🚀 ~ searchList ~ result:", result)
  return { result, total: count };
};

export const removeBook = async (id: number) => {
  return deleteBook(id)
}

export const actions: any[] = [
  { icon: 'clarity:star-line', text: '156', color: '#018ffb' },
  { icon: 'bx:bxs-like', text: '156', color: '#459ae8' },
  { icon: 'bx:bxs-message-dots', text: '2', color: '#42d27d' },
];

export const schemas: FormSchema[] = [
  {
    field: 'name',
    component: 'Input',
    label: '图书名称',
    colProps: {
      span: 8,
    },
    // componentProps: {
    //   onChange: (e: any) => {
    //     console.log(e);
    //   },
    // },
  },
  {
    field: 'author',
    component: 'Input',
    label: '作者',
    colProps: {
      span: 8,
    },
  },
];
